﻿using Anke.SHManage.MSSQLDAL;
using Anke.SHManage.Utility;
using Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    public class AmbulanceDAL
    {
        string AmbulanceDaiMing = AppConfig.GetConfigString("AmbulanceDaiMing");
        string AmbulanceRenWu = AppConfig.GetConfigString("AmbulanceRenWu");
        string AmbulanceZanTing = AppConfig.GetConfigString("AmbulanceZanTing");
        string AmbulanceXiaBan = AppConfig.GetConfigString("AmbulanceXiaBan");
        string ISGanBao = AppConfig.GetConfigString("ISGanBao");
        string OnlyLoadDutyAmb = AppConfig.GetConfigString("OnlyLoadDutyAmb");

        /// <summary>
        /// 获取车辆信息列表
        /// </summary>
        /// <param name="pageSize"></param>
        /// <param name="pageIndex"></param>
        /// <param name="CenterID"></param>
        /// <param name="StationID"></param>
        /// <param name="GroupID"></param>
        /// <param name="RealSign"></param>
        /// <param name="isDaiMing"></param>
        /// <param name="isRenWu"></param>
        /// <param name="isZanTing"></param>
        /// <param name="isXiaBan"></param>
        /// <returns></returns>
        public object GetAmbulanceList(int pageSize, int pageIndex, string CenterID, string StationID, string GroupID, string RealSign, bool isDaiMing, bool isRenWu, bool isZanTing, bool isXiaBan)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(@"select distinct ta.车辆编码,ta.实际标识,ta.车牌号码,ts.名称 as 分站,tzas.名称 as 工作状态,ta.随车电话,GPS状态 = case when ta.是否在线 = 1 then '在线' else '离线' end 
                        ,ta.任务流水号,dbo.GetNameWorkStr(ta.任务编码,3) as 司机工号,dbo.GetNameWorkStr(ta.任务编码,4) as 医生工号,dbo.GetNameWorkStr(ta.任务编码,5) as 护士工号
                        ,dbo.GetNameWorkStr(ta.任务编码,6) as 担架员工号,ta.按键时刻,ta.当班执行任务数,ta.工作状态编码,tzat.名称 as 车辆类型,tzal.名称 as 车辆等级,ta.任务编码,tt.生成任务时刻,tt.完成时刻
                        ,暂停调用原因=(case when 工作状态编码=9 then tzpr.名称 else '' end)
                        --,tpr.医院名称
                        ,tae.事件名称,tt.返回站中时刻
                        into #tempA                        
                        from TAmbulance ta
                        left join TStation ts on ta.分站编码 = ts.编码
						left join TCenter tc on tc.编码=ts.中心编码
                        left join TZAmbulanceState tzas on ta.工作状态编码 = tzas.编码
                        left join TZAmbulanceType tzat on ta.车辆类型编码 = tzat.编码
                        left join TZAmbulanceLevel tzal on ta.车辆等级编码 = tzal.编码
                        left join TTask tt on ta.任务编码 = tt.任务编码
						left join TAlarmEvent tae on tae.事件编码=tt.事件编码
                        left join TPauseRecord tpr on tpr.车辆编码=ta.车辆编码 and tpr.暂停时刻=(select 暂停时刻=max(暂停时刻) from TPauseRecord where 车辆编码=ta.车辆编码)
						left join TZPauseReason tzpr on tzpr.编码=tpr.暂停原因编码 
                        where ta.是否有效 = 1 ");

            WhereClauseUtility.AddStringEqual("ts.中心编码", CenterID, sb);
            WhereClauseUtility.AddStringEqual("ts.编码", StationID, sb);
            WhereClauseUtility.AddInSelectQuery("ta.分组编码", GroupID, sb);
            WhereClauseUtility.AddStringLike("ta.实际标识", RealSign, sb);
            if (isDaiMing == true || isRenWu == true || isZanTing == true || isXiaBan == true)
            {
                sb.Append(" And ( ");
                if (isDaiMing == true)
                {
                    sb.Append(" ta.工作状态编码 IN (" + AmbulanceDaiMing + ") Or");
                }
                if (isRenWu == true)
                {
                    sb.Append(" ta.工作状态编码 IN (" + AmbulanceRenWu + ") Or");
                }
                if (isZanTing == true)
                {
                    sb.Append(" ta.工作状态编码 IN (" + AmbulanceZanTing + ") Or");
                }
                if (isXiaBan == true)
                {
                    sb.Append(" ta.工作状态编码 IN (" + AmbulanceXiaBan + ") Or");
                }
                sb.Remove(sb.Length - 2, 2);//去除最后一个Or
                sb.Append(" ) ");
            }

            sb.Append(@"
                    select identity(int,1,1) as 行号,* into #temp from #tempA where 1=1 ");
            sb.Append(@"
                    order by 分站,工作状态编码 ");
            sb.Append(@"
                    select top " + pageSize + " A.*  from #temp A where 行号>" + (pageIndex - 1) * pageSize + " order by 行号 ");
            sb.Append(@"
                    SELECT count(*) FROM #temp t
                    drop table #tempA,#temp  ");
            List<AmbulanceInfo> list = new List<AmbulanceInfo>();
            try
            {
                DataSet ds = SqlHelper.ExecuteDataSet(SqlHelper.AttemperConnectionString, CommandType.Text, sb.ToString(), null);
                if (ds.Tables[0].Rows.Count > 0)
                {

                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {

                        AmbulanceInfo info = new AmbulanceInfo();
                        info.AmbulanceCode = dr["车辆编码"].ToString();
                        info.GPSState = dr["GPS状态"].ToString();
                        info.RealSign = dr["实际标识"].ToString();
                        info.Station = dr["分站"].ToString();
                        info.Tel = dr["随车电话"].ToString();
                        info.WorkState = dr["工作状态"].ToString();
                        info.TaskNo = dr["任务流水号"].ToString();
                        info.TaskNum = dr["当班执行任务数"].ToString();
                        info.AmbulanceNum = dr["车牌号码"].ToString();
                        info.Driver = dr["司机工号"].ToString();
                        info.Doctor = dr["医生工号"].ToString();
                        info.Nurse = dr["护士工号"].ToString();
                        info.Stretcher = dr["担架员工号"].ToString();
                        info.KeyTime = dr["按键时刻"] != DBNull.Value ? Convert.ToDateTime(dr["按键时刻"]) : new Nullable<DateTime>();
                        info.WorkStateCode = dr["工作状态编码"].ToString();
                        info.AmbulanceType = dr["车辆类型"].ToString();
                        info.AmbulanceLevel = dr["车辆等级"].ToString();
                        info.TaskCode = dr["任务编码"].ToString();
                        info.StartTime = dr["生成任务时刻"] != DBNull.Value ? Convert.ToDateTime(dr["生成任务时刻"]).ToString("yyyy-MM-dd HH:mm:ss") : "";
                        info.EndTime = dr["完成时刻"] != DBNull.Value ? Convert.ToDateTime(dr["完成时刻"]).ToString("yyyy-MM-dd HH:mm:ss") : "";
                        info.PauseReason = dr["暂停调用原因"].ToString();
                        info.EventName = dr["事件名称"].ToString(); //add2021-01-18 plq
                        info.ReturnStationTime = dr["返回站中时刻"] != DBNull.Value ? Convert.ToDateTime(dr["返回站中时刻"]).ToString("yyyy-MM-dd HH:mm:ss") : "";//add2021-01-18 plq
                        //info.PauseHospital = dr["医院名称"].ToString();
                        info.PauseHospital = ""; //add2021-04-15 plq 适配云南省 TPauseRecord无医院名称字段，默认为空
                        list.Add(info);
                    }
                }
                int total = Convert.ToInt32(ds.Tables[1].Rows[0][0]);
                var result = new { total = total, rows = list };
                return result;
            }
            catch (Exception ex)
            {
                LogUtility.Error("AmbulanceDAL/GetAmbulanceList", ex.Message);
                return null;
            }

        }

        /// <summary>
        /// 获取实时数据统计---待派任务数
        /// </summary>
        /// <returns></returns>
        public object GetTalarmEventInfo(string CenterID)
        {
            StringBuilder sb = new StringBuilder();
            var start = DateTime.Now.ToString("yyyy-MM-dd 00:00:00");
            var end = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd 00:00:00");

            //add2021-01-20 plq 添加中心筛选条件
            sb.Append(@"select identity(int,1,1) as 行号,
                isnull(sum(case when 是否挂起 = 1 and 事件类型编码 = 0 then 1 else 0  end),0) as JiJiu,
                isnull(sum(case when 是否挂起 = 1 and 事件类型编码 = 2  then 1 else 0  end),0) as ZhuanYuan,
                isnull(sum(case when 是否挂起 = 1 and 事件类型编码 = 1 and 首次受理时刻 >='" + start + "' and 首次受理时刻 <'" + end + @"' then 1 else 0  end),0) as FeiJiJiu 
                into #tempA
                from TAlarmEvent 
                where 1=1
               ");
            WhereClauseUtility.AddStringEqual("中心编码", CenterID, sb); //2021-01-20 plq
//            sb.Append(@"
//                     select identity(int,1,1) as 行号,COUNT(编码) as YuYue 
//                     into #tempB
//                     from dbo.TBooking 
//                     where  预约时间>='" + start + "' and 预约时间<'" + end + @"' and (事件编码 is null or 事件编码='') and 是否撤销=0 ");

            //add2021-04-15 plq 适配云南省TBooking表无 是否撤销 字段，改为 是否有效为1
            sb.Append(@"
                     select identity(int,1,1) as 行号,COUNT(编码) as YuYue 
                     into #tempB
                     from dbo.TBooking 
                     where  预约时间>='" + start + "' and 预约时间<'" + end + @"' and (事件编码 is null or 事件编码='') and 是否有效=1 ");
            WhereClauseUtility.AddStringEqual("中心编码", CenterID, sb); //2021-01-20 plq
            sb.Append(@"
                     select JiJiu,ZhuanYuan,FeiJiJiu,YuYue from #tempA A
                     left join #tempB B on a.行号=b.行号
                     drop table #tempA
                     drop table #tempB ");
            try
            {
                DataSet ds = SqlHelper.ExecuteDataSet(SqlHelper.AttemperConnectionString, CommandType.Text, sb.ToString(), null);
                List<TalarmEventInfo> list = new List<TalarmEventInfo>();
                if (ds.Tables[0].Rows.Count > 0)
                {
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        TalarmEventInfo info = new TalarmEventInfo();
                        info.ID = "1";
                        info.Name = "急救";
                        info.Value = dr["JiJiu"] == DBNull.Value ? 0 : Convert.ToInt32(dr["JiJiu"]);
                        list.Add(info);
                        info = new TalarmEventInfo();
                        info.ID = "2";
                        info.Name = "转院";
                        info.Value = dr["ZhuanYuan"] == DBNull.Value ? 0 : Convert.ToInt32(dr["ZhuanYuan"]);
                        list.Add(info);
                        info = new TalarmEventInfo();
                        info.ID = "3";
                        info.Name = "非急救当天";
                        info.Value = dr["FeiJiJiu"] == DBNull.Value ? 0 : Convert.ToInt32(dr["FeiJiJiu"]);
                        list.Add(info);
                        info = new TalarmEventInfo();
                        info.ID = "4";
                        info.Name = "预约";
                        info.Value = dr["YuYue"] == DBNull.Value ? 0 : Convert.ToInt32(dr["YuYue"]);
                        list.Add(info);
                    }
                }
                return list;
            }
            catch (Exception ex)
            {
                LogUtility.Error("AmbulanceDAL/GetTalarmEventInfo", ex.Message);
                return null;
            }

        }

        /// <summary>
        /// 获取历史呼救信息列表---因为目前来看一次受理最多对应一次任务，所以应该是历史受理信息列表
        /// </summary>
        /// <param name="pageSize"></param>
        /// <param name="pageIndex"></param>
        /// <param name="StartTime"></param>
        /// <param name="EndTime"></param>
        /// <param name="LocalAddress"></param>
        /// <param name="SendAddress"></param>
        /// <param name="Tel"></param>
        /// <param name="UserId"></param>
        /// <returns></returns>
        public object GetTalarmEventList(int pageSize, int pageIndex, DateTime StartTime, DateTime EndTime, string LocalAddress, string SendAddress, string Tel, string UserId, string CenterID)
        {
            StringBuilder sb = new StringBuilder();
//            sb.Append(@"select distinct tzae.名称 as 事件类型,tae.事件名称,tae.事件类型编码,tac.现场地址,tac.患者姓名,tac.联系电话,tac.送往地点,tae.首次受理时刻,tac.主诉,tac.呼救电话,tac.开始受理时刻,tzao.名称 as 来源,tae.事件来源编码,tp.姓名 as 受理调度员,tac.责任受理人编码,tae.受理次数,tae.执行任务总数,tac.国籍,tac.等车地址,ta.实际标识,
//                    ta.车辆编码,tac.X坐标,tac.Y坐标,tac.是否标注,tae.事件编码,tt.生成任务时刻,tt.完成时刻
//                    into #tempA
//                    from TAlarmEvent tae
//                    left join TAcceptEvent tac on tae.事件编码 = tac.事件编码
//                    --left join TPerson tp on tae.首次调度员编码= tp.编码
//                    left join TPerson tp on tac.责任受理人编码= tp.编码
//                    left join TZAlarmEventOrigin tzao on tae.事件来源编码=tzao.编码 
//                    left join TZAlarmEventType tzae on tae.事件类型编码 = tzae.编码
//                    left join TTask tt on tac.事件编码 = tt.事件编码 and tac.受理序号 = tt.受理序号
//					left join TAmbulance ta on tt.车辆编码 = ta.车辆编码 
//                    where tae.是否测试 = 0 ");
//            WhereClauseUtility.AddDateTimeGreaterThan("tac.开始受理时刻", StartTime, sb);
//            WhereClauseUtility.AddDateTimeLessThan("tac.开始受理时刻", EndTime, sb);
//            WhereClauseUtility.AddStringLike("tac.现场地址", LocalAddress, sb);
//            WhereClauseUtility.AddStringLike("tac.送往地点", SendAddress, sb);
//            //WhereClauseUtility.AddInSelectQuery("tae.首次调度员编码", UserId, sb);
//            WhereClauseUtility.AddInSelectQuery("tac.责任受理人编码", UserId, sb);
//            WhereClauseUtility.AddStringEqual("tae.中心编码", CenterID, sb); //2021-01-20 plq
//            sb.Append(@"
//                    select identity(int,1,1) as 行号,* into #temp from #tempA ");
//            sb.Append(@"
//                    order by 开始受理时刻 desc ");
//            sb.Append(@"
//                    select top " + pageSize + " A.*  from #temp A where 行号>" + (pageIndex - 1) * pageSize + " order by 行号 ");
//            sb.Append(@"
//                    SELECT count(*) FROM #temp t
//                    drop table #tempA,#temp  ");

            //add2021-03-24 plq 解决直接左联任务表查询速度很慢的问题，先根据条件查出事件列表，再临时表关联任务表查询，提高查询速度
            sb.Append(@"select distinct tzae.名称 as 事件类型,tae.事件名称,tae.事件类型编码,tac.现场地址,tac.患者姓名,tac.联系电话,tac.送往地点,tae.首次受理时刻,tac.主诉
                    ,tac.呼救电话,tac.开始受理时刻,tzao.名称 as 来源,tae.事件来源编码,tp.姓名 as 受理调度员,tac.责任受理人编码,tae.受理次数,tae.执行任务总数,tac.国籍,tac.等车地址
                    ,tac.X坐标,tac.Y坐标,tac.是否标注,tac.事件编码,tac.受理序号
                    into #tempA
                    from TAlarmEvent tae
                    left join TAcceptEvent tac on tae.事件编码 = tac.事件编码
                    --left join TPerson tp on tae.首次调度员编码= tp.编码
                    left join TPerson tp on tac.责任受理人编码= tp.编码
                    left join TZAlarmEventOrigin tzao on tae.事件来源编码=tzao.编码 
                    left join TZAlarmEventType tzae on tae.事件类型编码 = tzae.编码
                    where tae.是否测试 = 0 ");
            WhereClauseUtility.AddDateTimeGreaterThan("tac.开始受理时刻", StartTime, sb);
            WhereClauseUtility.AddDateTimeLessThan("tac.开始受理时刻", EndTime, sb);
            WhereClauseUtility.AddStringLike("tac.现场地址", LocalAddress, sb);
            WhereClauseUtility.AddStringLike("tac.送往地点", SendAddress, sb);
            //WhereClauseUtility.AddInSelectQuery("tae.首次调度员编码", UserId, sb);
            WhereClauseUtility.AddInSelectQuery("tac.责任受理人编码", UserId, sb);
            WhereClauseUtility.AddStringEqual("tae.中心编码", CenterID, sb); //2021-01-20 plq

            sb.Append(@"
                    select identity(int,1,1) as 行号,tpa.* ,tt.生成任务时刻,tt.完成时刻
                    ,ta.实际标识,ta.车辆编码
                    into #temp
                    from  #tempA tpa
                    left join TTask tt on tpa.事件编码 = tt.事件编码 and tpa.受理序号 = tt.受理序号
                    left join TAmbulance ta on tt.车辆编码 = ta.车辆编码  ");
            sb.Append(@"
                    order by 开始受理时刻 desc ");
            sb.Append(@"
                    select top " + pageSize + " A.*  from #temp A where 行号>" + (pageIndex - 1) * pageSize + " order by 行号 ");
            sb.Append(@"
                    SELECT count(*) FROM #temp t
                    drop table #tempA,#temp  ");

            List<HistoryEventInfo> list = new List<HistoryEventInfo>();
            try
            {
                DataSet ds = SqlHelper.ExecuteDataSet(SqlHelper.AttemperConnectionString, CommandType.Text, sb.ToString(), null);
                if (ds.Tables[0].Rows.Count > 0)
                {

                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {

                        HistoryEventInfo info = new HistoryEventInfo();
                        info.EventType = dr["事件类型"].ToString();
                        info.EventTypeID = dr["事件类型编码"].ToString();
                        info.LocalAddress = dr["现场地址"].ToString();
                        info.PatientName = dr["患者姓名"].ToString();
                        info.Tel = dr["联系电话"].ToString();
                        info.SendAddress = dr["送往地点"].ToString();
                        info.FirtEventTime = Convert.ToDateTime(dr["开始受理时刻"]);
                        info.ZhuSu = dr["主诉"].ToString();
                        info.HuJiuTel = dr["呼救电话"].ToString();
                        info.OriginType = dr["来源"].ToString();
                        info.OriginTypeID = dr["事件来源编码"].ToString();
                        //info.DispatcherName = dr["首调人员"].ToString();
                        //info.DispatcherID = dr["首次调度员编码"].ToString();
                        info.DispatcherName = dr["受理调度员"].ToString();
                        info.DispatcherID = dr["责任受理人编码"].ToString();
                        info.TAlarmNum = dr["受理次数"].ToString();
                        info.TAlarmTotal = dr["执行任务总数"].ToString();
                        info.Country = dr["国籍"].ToString();
                        info.WaitAddress = dr["等车地址"].ToString();
                        info.AmbulanceNumber = dr["实际标识"].ToString();
                        info.AmbulanceCode = dr["车辆编码"].ToString();
                        info.Latitude = Convert.ToDouble(dr["Y坐标"]);
                        info.Longitude = Convert.ToDouble(dr["X坐标"]);
                        info.IsMark = Convert.ToBoolean(dr["是否标注"]);
                        info.EventName = dr["事件名称"].ToString();
                        info.EventCode = dr["事件编码"].ToString();
                        info.StartTime = dr["生成任务时刻"] == DBNull.Value ? "" : Convert.ToDateTime(dr["生成任务时刻"]).ToString("yyyy-MM-dd HH:mm:ss");
                        info.EndTime = dr["完成时刻"] == DBNull.Value ? "" : Convert.ToDateTime(dr["完成时刻"]).ToString("yyyy-MM-dd HH:mm:ss");
                        list.Add(info);
                    }
                    //GPS经纬度坐标系转换 wgs转百度 start
                    foreach (var item in list)
                    {
                        double[] bdCoor = CoorConvert.Wgs2bd(item.Latitude, item.Longitude);
                        item.Longitude = bdCoor[1];
                        item.Latitude = bdCoor[0];
                    }
                    //End
                }
                int total = Convert.ToInt32(ds.Tables[1].Rows[0][0]);
                var result = new { total = total, rows = list };
                return result;
            }
            catch (Exception ex)
            {
                LogUtility.Error("AmbulanceDAL/GetTalarmEventList", ex.Message);
                return null;
            }

        }

        /// <summary>
        /// 获取实时数据统计---当班车辆数(车辆状态分类)and 分站编码<>'001' 
        /// </summary>
        /// <returns></returns>
        public object GetAmbulanceNum(string CenterID)
        {
            StringBuilder sb = new StringBuilder();
            var groupCode = ISGanBao == "true" ? AppConfig.GetConfigInt("SubAmbGroupCode") : AppConfig.GetConfigInt("MainAmbGroupCode");

            //add2021-01-20 plq 添加中心筛选
            sb.Append(@"select isnull(sum(case when 工作状态编码 in (" + AmbulanceRenWu + @") then 1 else 0  end),0) as RenWu, 
                        isnull(sum(case when 工作状态编码 =6 then 1 else 0  end),0) as TuZhongDaiMing ,
                        isnull(sum(case when 工作状态编码 =7 then 1 else 0  end),0) as ZhanNeiDaiMing ,
                        isnull(sum(case when 工作状态编码 =9 then 1 else 0  end),0) as ZanTing
                        from TAmbulance ta
                        left join TStation ts on ta.分站编码=ts.编码
                        where ta.是否有效=1 and ta.分组编码 = '" + groupCode + "'");

            WhereClauseUtility.AddStringEqual("ts.中心编码", CenterID, sb);

            try
            {
                DataSet ds = SqlHelper.ExecuteDataSet(SqlHelper.AttemperConnectionString, CommandType.Text, sb.ToString(), null);
                List<AmbulanceNum> list = new List<AmbulanceNum>();
                if (ds.Tables[0].Rows.Count > 0)
                {
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        AmbulanceNum info = new AmbulanceNum();
                        info.name = "任务中";
                        info.value = dr["RenWu"] == DBNull.Value ? 0 : Convert.ToInt32(dr["RenWu"]);
                        info.unit = "辆";
                        list.Add(info);
                        info = new AmbulanceNum();
                        info.name = "途中待命";
                        info.value = dr["TuZhongDaiMing"] == DBNull.Value ? 0 : Convert.ToInt32(dr["TuZhongDaiMing"]);
                        info.unit = "辆";
                        list.Add(info);
                        info = new AmbulanceNum();
                        info.name = "站内待命";
                        info.value = dr["ZhanNeiDaiMing"] == DBNull.Value ? 0 : Convert.ToInt32(dr["ZhanNeiDaiMing"]);
                        info.unit = "辆";
                        list.Add(info);
                        info = new AmbulanceNum();
                        info.name = "暂停调用";
                        info.value = dr["ZanTing"] == DBNull.Value ? 0 : Convert.ToInt32(dr["ZanTing"]);
                        info.unit = "辆";
                        list.Add(info);
                    }
                }
                return list;
            }
            catch (Exception ex)
            {
                LogUtility.Error("AmbulanceDAL/GetAmbulanceNum", ex.Message);
                return null;
            }

        }

        /// <summary>
        /// 获取车辆最后GPS
        /// </summary>
        /// <returns></returns>
        public object GetAmbLastGPS(string CenterID)
        {
            StringBuilder stringBuilder = new StringBuilder();
            SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(SqlHelper.AttemperConnectionString);
            stringBuilder.Append(@"select tgs.车辆编码,tgs.实际标识,tgs.任务编码,tzas.名称,tgs.工作状态编码,tgs.时间,tgs.经度,tgs.纬度,
                tgs.高度,tgs.方向,tgs.速度,ta.随车电话,ta.司机,ta.医生,ta.护士,ta.担架工,ta.抢救员,ta.分站编码,ts.名称 as 分站名称,tt.实际送往地点
                from TGPSLast tgs ");
            //left join TAmbulance ta on tgs.车辆编码 = ta.车辆编码 
            //left join TZAmbulanceState tzas on tgs.工作状态编码 = tzas.编码
            //left join TStation ts on ta.分站编码 = ts.编码
            //left join TTask tt on ta.任务编码 = tt.任务编码
            stringBuilder.Append(" left join ").Append(builder.InitialCatalog).Append(".dbo.TAmbulance ta on tgs.车辆编码 = ta.车辆编码  ");
            stringBuilder.Append(" left join ").Append(builder.InitialCatalog).Append(".dbo.TZAmbulanceState tzas on tgs.工作状态编码 = tzas.编码 ");
            stringBuilder.Append(" left join ").Append(builder.InitialCatalog).Append(".dbo.TStation ts on ta.分站编码 = ts.编码 ");
            stringBuilder.Append(" left join ").Append(builder.InitialCatalog).Append(".dbo.TTask tt on ta.任务编码 = tt.任务编码 ");
            stringBuilder.Append(@" where ta.是否有效 = 1 ");
            if (ISGanBao == "true")
            {
                //stringBuilder.Append(@" and ta.分组编码 = 1 ");
                stringBuilder.Append(@" and ta.分组编码 =" + AppConfig.GetConfigInt("SubAmbGroupCode") + " ");
            }
            if (OnlyLoadDutyAmb == "true")
            {
                stringBuilder.Append(@" and tgs.工作状态编码 <> 8 ");
            }
            //add2021-01-20 plq 中心筛选
            WhereClauseUtility.AddStringEqual("ts.中心编码", CenterID, stringBuilder);

            try
            {
                DataSet ds = SqlHelper.ExecuteDataSet(SqlHelper.GPSConnectionString, CommandType.Text, stringBuilder.ToString(), null);
                DataTable dt = ds.Tables[0];

                var query = from a in dt.AsEnumerable()
                            select new AmbLastGPSInfo()
                            {
                                AmbulanceCode = a.Field<string>("车辆编码"),
                                RealSign = a.Field<string>("实际标识"),
                                WorkState = a.Field<string>("名称"),
                                WorkStateCode = a.Field<int>("工作状态编码"),
                                Time = a.Field<DateTime>("时间"),
                                Longitude = a.Field<double>("经度"),
                                Latitude = a.Field<double>("纬度"),
                                Height = a.Field<double>("高度"),
                                Speed = a.Field<double>("速度"),
                                Direction = a.Field<double>("方向"),
                                Tel = a.Field<string>("随车电话"),
                                Driver = a.Field<string>("司机"),
                                Doctor = a.Field<string>("医生"),
                                Nurse = a.Field<string>("护士"),
                                Litter = a.Field<string>("担架工"),
                                EventName = a.Field<string>("抢救员"),
                                StationCode = a.Field<string>("分站编码"),
                                StationName = a.Field<string>("分站名称"),
                                RealLocal = a.Field<string>("实际送往地点"),
                            };
                List<AmbLastGPSInfo> GPSInfoList = query.ToList();
                //GPS经纬度坐标系转换 wgs转百度 start
                foreach (var item in GPSInfoList)
                {
                    double[] bdCoor = CoorConvert.Wgs2bd(item.Latitude, item.Longitude);
                    item.Longitude = bdCoor[1];
                    item.Latitude = bdCoor[0];
                }
                //end
                var result = new { total = GPSInfoList.Count, rows = GPSInfoList };
                return result;
            }
            catch (Exception ex)
            {
                LogUtility.Error("AmbulanceDAL/GetAmbLastGPS()", "查询失败：" + ex.Message);
                return null;
            }
        }

        /// <summary>
        /// 获取分站坐标信息
        /// </summary>
        /// <returns></returns>
        public object GetStationInfo(string CenterID)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(@"select 编码,名称,X坐标,Y坐标 from TStation where 是否有效=1 and 是否标注=1");
            //add2021-01-20 plq
            WhereClauseUtility.AddStringEqual("中心编码", CenterID, sb);

            try
            {
                DataSet ds = SqlHelper.ExecuteDataSet(SqlHelper.AttemperConnectionString, CommandType.Text, sb.ToString(), null);
                DataTable dt = ds.Tables[0];

                var query = from a in dt.AsEnumerable()
                            select new StationInfo()
                            {
                                StationCode = a.Field<string>("编码"),
                                StationName = a.Field<string>("名称"),
                                Longitude = a.Field<double>("X坐标"),
                                Latitude = a.Field<double>("Y坐标"),
                            };
                List<StationInfo> GPSInfoList = query.ToList();
                //GPS经纬度坐标系转换 wgs转百度 start
                foreach (var item in GPSInfoList)
                {
                    double[] bdCoor = CoorConvert.Wgs2bd(item.Latitude, item.Longitude);
                    item.Longitude = bdCoor[1];
                    item.Latitude = bdCoor[0];
                }
                //end
                var result = new { total = GPSInfoList.Count, rows = GPSInfoList };
                return result;
            }
            catch (Exception ex)
            {
                LogUtility.Error("AmbulanceDAL/GetStationInfo()", "查询失败：" + ex.Message);
                return null;
            }
        }

        /// <summary>
        /// 获取医院坐标信息
        /// </summary>
        /// <returns></returns>
        public object GetHospitalInfo(string CenterID)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(@"select 编码,名称,X坐标,Y坐标 from THospitalInfo where 是否有效=1 and 是否标注=1");
            //add2021-01-20 plq
            WhereClauseUtility.AddStringEqual("中心编码", CenterID, sb);

            try
            {
                DataSet ds = SqlHelper.ExecuteDataSet(SqlHelper.AttemperConnectionString, CommandType.Text, sb.ToString(), null);
                DataTable dt = ds.Tables[0];

                var query = from a in dt.AsEnumerable()
                            select new HospitalInfo()
                            {
                                HospitalCode = a.Field<string>("编码"),
                                HospitalName = a.Field<string>("名称"),
                                Longitude = a.Field<double>("X坐标"),
                                Latitude = a.Field<double>("Y坐标"),
                            };
                List<HospitalInfo> GPSInfoList = query.ToList();
                //GPS经纬度坐标系转换 wgs转百度 start
                foreach (var item in GPSInfoList)
                {
                    double[] bdCoor = CoorConvert.Wgs2bd(item.Latitude, item.Longitude);
                    item.Longitude = bdCoor[1];
                    item.Latitude = bdCoor[0];
                }
                //end
                var result = new { total = GPSInfoList.Count, rows = GPSInfoList };
                return result;
            }
            catch (Exception ex)
            {
                LogUtility.Error("AmbulanceDAL/GetHospitalInfo()", "查询失败：" + ex.Message);
                return null;
            }
        }

        /// <summary>
        /// 获取当前事件呼救定位
        /// </summary>
        /// <param name="TaskCode"></param>
        /// <returns></returns>
        public object GetXYInfoByTaskCode(string TaskCode)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(@"SELECT top 1 tac.事件编码,tac.现场地址,tac.X坐标,tac.Y坐标,tac.联系电话,tac.患者姓名,tac.是否标注,tae.事件名称
                FROM TAcceptEvent tac
                left join TAlarmEvent tae on tac.事件编码 = tae.事件编码 and tac.受理序号 = tae.受理次数
                where tae.事件编码= (SELECT 事件编码 FROM TTask where 任务编码='" + TaskCode + "')");
            try
            {
                DataSet ds = SqlHelper.ExecuteDataSet(SqlHelper.AttemperConnectionString, CommandType.Text, sb.ToString(), null);
                DataTable dt = ds.Tables[0];

                var query = from a in dt.AsEnumerable()
                            select new ByTaskCodeInfo()
                            {
                                EventCode = a.Field<string>("事件编码"),
                                LocalAddress = a.Field<string>("现场地址"),
                                Longitude = a.Field<double>("X坐标"),
                                Latitude = a.Field<double>("Y坐标"),
                                Tel = a.Field<string>("联系电话"),
                                PatientName = a.Field<string>("患者姓名"),
                                IsMark = a.Field<Boolean>("是否标注"),
                                EventName = a.Field<string>("事件名称"),
                            };
                List<ByTaskCodeInfo> GPSInfoList = query.ToList();
                //GPS经纬度坐标系转换 wgs转百度 start
                foreach (var item in GPSInfoList)
                {
                    double[] bdCoor = CoorConvert.Wgs2bd(item.Latitude, item.Longitude);
                    item.Longitude = bdCoor[1];
                    item.Latitude = bdCoor[0];
                }
                //end
                var result = new { total = GPSInfoList.Count, rows = GPSInfoList };
                return result;
            }
            catch (Exception ex)
            {
                LogUtility.Error("AmbulanceDAL/GetXYInfoByTaskCode()", "查询失败：" + ex.Message);
                return null;
            }
        }
        //获取车辆GPS列表
        public object GetGpsTrack(string AmbulanceCode, DateTime StartTime, DateTime EndTime, bool IsFilterStop)
        {
            StringBuilder sb = new StringBuilder();
            List<GpsTrackList> lstGpsTrack = null;
            SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(SqlHelper.AttemperConnectionString);
            sb.Append(@"select 车辆编码,实际标识,工作状态编码,tzas.名称 as 工作状态,经度,纬度,高度,速度,方向,时间 from TGPS tgps ");
            //left join TZAmbulanceState tzas on tgps.工作状态编码 = tzas.编码  where 1 = 1
            sb.Append(" left join ").Append(builder.InitialCatalog).Append(".dbo.TZAmbulanceState tzas on tgps.工作状态编码 = tzas.编码 where 1 = 1");
            WhereClauseUtility.AddDateTimeGreaterThan("tgps.时间", StartTime, sb);
            WhereClauseUtility.AddDateTimeLessThan("tgps.时间", EndTime, sb);
            WhereClauseUtility.AddStringEqual("tgps.车辆编码", AmbulanceCode, sb);
            try
            {
                DataSet ds = SqlHelper.ExecuteDataSet(SqlHelper.GPSConnectionString, CommandType.Text, sb.ToString(), null);
                DataTable dt = ds.Tables[0];
                if (IsFilterStop)
                {
                    lstGpsTrack = new List<GpsTrackList>();
                    double lastSpeed = 1;//上个速度
                    foreach (DataRow dr in dt.Rows)
                    {
                        double thisSpeed = Convert.ToDouble(dr["速度"]);
                        if (thisSpeed < 0.1 && lastSpeed < 0.1) //判断是不是某段轨迹点中的第一个速度为0的点
                        {
                            continue;//过滤掉
                        }

                        lastSpeed = thisSpeed;
                        lstGpsTrack.Add(new GpsTrackList()
                        {
                            Code = Convert.ToString(dr["车辆编码"]),
                            RealSign = Convert.ToString(dr["实际标识"]),
                            WorkStateId = Convert.ToInt16(dr["工作状态编码"]),
                            WorkState = Convert.ToString(dr["工作状态"]),
                            Longitude = Convert.ToDouble(dr["经度"]),
                            Latitude = Convert.ToDouble(dr["纬度"]),
                            Height = Convert.ToDouble(dr["高度"]),
                            Speed = Convert.ToDouble(dr["速度"]),
                            Direction = Convert.ToDouble(dr["方向"]),
                            GpsTime = Convert.ToDateTime(dr["时间"]).ToString("yyyy-MM-dd HH:mm:ss")
                        });
                    }
                    //GPS经纬度坐标系转换 wgs转百度 start
                    foreach (var item in lstGpsTrack)
                    {
                        double[] bdCoor = CoorConvert.Wgs2bd(item.Latitude, item.Longitude);
                        item.Longitude = bdCoor[1];
                        item.Latitude = bdCoor[0];
                    }
                    //end
                    var result = new { total = lstGpsTrack.Count, rows = lstGpsTrack };
                    return result;
                }
                else
                {
                    var query = from a in dt.AsEnumerable()
                                select new GpsTrackList()
                                {
                                    Code = a.Field<string>("车辆编码"),
                                    RealSign = a.Field<string>("实际标识"),
                                    WorkStateId = a.Field<int>("工作状态编码"),
                                    WorkState = a.Field<string>("工作状态"),
                                    Longitude = a.Field<double>("经度"),
                                    Latitude = a.Field<double>("纬度"),
                                    Height = a.Field<double>("高度"),
                                    Speed = a.Field<double>("速度"),
                                    Direction = a.Field<double>("方向"),
                                    GpsTime = a.Field<DateTime>("时间").ToString("yyyy-MM-dd HH:mm:ss")
                                };
                    lstGpsTrack = query.ToList();
                    //GPS经纬度坐标系转换 wgs转百度 start
                    foreach (var item in lstGpsTrack)
                    {
                        double[] bdCoor = CoorConvert.Wgs2bd(item.Latitude, item.Longitude);
                        item.Longitude = bdCoor[1];
                        item.Latitude = bdCoor[0];
                    }
                    //end
                    var result = new { total = lstGpsTrack.Count, rows = lstGpsTrack };
                    return result;
                }
            }
            catch (Exception ex)
            {
                LogUtility.Error("AmbulanceDAL/GetGpsTrack", ex.Message);
            }
            return null;
        }
        //地图加载获取 事件坐标信息
        public object GetExcuteAlarmEventInfo(string CenterID)
        {
            string eventCodeB = "";
            eventCodeB = DateTime.Now.AddDays(-3).ToString("yyyyMMddHHmmss") + "00";
            StringBuilder sb = new StringBuilder();
            sb.Append(@"select ae.事件编码,事件名称,患者姓名,首次受理时刻, acc.X坐标, acc.Y坐标, ae.首次呼救电话,ae.是否挂起
                                from TAlarmEvent ae
                                join TAcceptEvent acc on ae.事件编码=acc.事件编码
                                where ae.事件编码>'" + eventCodeB + @"' 
                                and (ae.当前执行任务数>0' or ae.是否挂起=1) and acc.受理序号=1 and ae.是否标注=1 ");
            //add2021-01-20 plq
            WhereClauseUtility.AddStringEqual("ae.中心编码", CenterID, sb); 
            try
            {
                DataSet ds = SqlHelper.ExecuteDataSet(SqlHelper.AttemperConnectionString, CommandType.Text, sb.ToString(), null);
                DataTable dt = ds.Tables[0];

                var query = from a in dt.AsEnumerable()
                            select new AlarmEventInfo()
                            {
                                EventCode = a.Field<string>("事件编码"),
                                EventName = a.Field<string>("事件名称"),
                                Longitude = a.Field<double>("X坐标"),
                                Latitude = a.Field<double>("Y坐标"),
                                Type = a.Field<bool>("是否挂起") == true ? 2 : 1,
                                FirstAlarmTel = a.Field<string>("首次呼救电话"),
                                PatientName = a.Field<string>("患者姓名")
                            };
                List<AlarmEventInfo> GPSInfoList = query.ToList();
                //GPS经纬度坐标系转换 wgs转百度 start
                foreach (var item in GPSInfoList)
                {
                    double[] bdCoor = CoorConvert.Wgs2bd(item.Latitude, item.Longitude);
                    item.Longitude = bdCoor[1];
                    item.Latitude = bdCoor[0];
                }
                //end
                var result = new { total = GPSInfoList.Count, rows = GPSInfoList };
                return result;
            }
            catch (Exception ex)
            {
                LogUtility.Error("AmbulanceDAL/GetExcuteAlarmEventInfo()", "查询失败：" + ex.Message);
                return null;
            }
        }


        /// <summary>
        /// 获取实时数据统计--当班车辆数(车辆等级分类)
        /// </summary>
        /// <returns></returns>
        public object GetDutyTypeAmbNum(string CenterID)
        {
            StringBuilder sb = new StringBuilder();
            var groupCode = ISGanBao == "true" ? AppConfig.GetConfigInt("SubAmbGroupCode") : AppConfig.GetConfigInt("MainAmbGroupCode");
            string NotFaAmbLevelCode = AppConfig.GetConfigString("NotFaAmbLevelCode"); //非急救车对应车辆等级编码
            string FaAmbLevelCode = AppConfig.GetConfigString("FaAmbLevelCode"); //急救车对应车辆等级编码
            string TransferAmbLevelCode = AppConfig.GetConfigString("TransferAmbLevelCode"); //转院车对应车辆等级编码

            //add2021-01-20 plq 添加中心筛选
            sb.Append(@"select isnull(sum(case when 车辆等级编码 in (" + NotFaAmbLevelCode + @") then 1 else 0  end),0) as FeiJiJiuChe, 
                        isnull(sum(case when 车辆等级编码 in (" + FaAmbLevelCode + @")  then 1 else 0  end),0) as JiJiuChe ,
                        isnull(sum(case when 车辆等级编码 in (" + TransferAmbLevelCode + @")  then 1 else 0  end),0) as ZhuYuanChe ,
                        isnull(sum(case when 车辆等级编码 not in (" + NotFaAmbLevelCode + "," + FaAmbLevelCode + "," + TransferAmbLevelCode + @")   then 1 else 0  end),0) as QiTa
                        from TAmbulance ta 
                        left join TStation ts on ta.分站编码=ts.编码
                        where ta.是否有效=1 and ta.工作状态编码!=8 and ta.分组编码 = '" + groupCode + "'"); //取当班车(状态不等于不能调用)

            WhereClauseUtility.AddStringEqual("ts.中心编码", CenterID, sb);
            try
            {
                DataSet ds = SqlHelper.ExecuteDataSet(SqlHelper.AttemperConnectionString, CommandType.Text, sb.ToString(), null);
                List<AmbulanceNum> list = new List<AmbulanceNum>();
                if (ds.Tables[0].Rows.Count > 0)
                {
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        AmbulanceNum info = new AmbulanceNum();
                        info.name = "急救车";
                        info.value = dr["JiJiuChe"] == DBNull.Value ? 0 : Convert.ToInt32(dr["JiJiuChe"]);
                        //info.unit = "辆";
                        list.Add(info);
                        info = new AmbulanceNum();
                        info.name = "转院车";
                        info.value = dr["ZhuYuanChe"] == DBNull.Value ? 0 : Convert.ToInt32(dr["ZhuYuanChe"]);
                        //info.unit = "辆";
                        list.Add(info);
                        info = new AmbulanceNum();
                        info.name = "非急救车";
                        info.value = dr["FeiJiJiuChe"] == DBNull.Value ? 0 : Convert.ToInt32(dr["FeiJiJiuChe"]);
                        //info.unit = "辆";
                        list.Add(info);
                        info = new AmbulanceNum();
                        info.name = "其他";
                        info.value = dr["QiTa"] == DBNull.Value ? 0 : Convert.ToInt32(dr["QiTa"]);
                        //info.unit = "辆";
                        list.Add(info);
                    }
                }
                return list;
            }
            catch (Exception ex)
            {
                LogUtility.Error("AmbulanceDAL/GetDutyTypeAmbNum()", "查询失败：" + ex.Message);
                return null;
            }

        }

        /// <summary>
        /// 获取实时数据统计--途中待命车辆数
        /// </summary>
        /// <returns></returns>
        public object GetWayStandByAmbNum(string CenterID)
        {
            StringBuilder sb = new StringBuilder();
            var groupCode = ISGanBao == "true" ? AppConfig.GetConfigInt("SubAmbGroupCode") : AppConfig.GetConfigInt("MainAmbGroupCode");
            string NotFaAmbLevelCode = AppConfig.GetConfigString("NotFaAmbLevelCode"); //非急救车对应车辆等级编码
            string FaAmbLevelCode = AppConfig.GetConfigString("FaAmbLevelCode"); //急救车对应车辆等级编码
            string TransferAmbLevelCode = AppConfig.GetConfigString("TransferAmbLevelCode"); //转院车对应车辆等级编码

            //add2021-01-20 plq 添加中心筛选
            sb.Append(@"select isnull(sum(case when 车辆等级编码 in (" + NotFaAmbLevelCode + @") then 1 else 0  end),0) as FeiJiJiuChe, 
                        isnull(sum(case when 车辆等级编码 in (" + FaAmbLevelCode + @")  then 1 else 0  end),0) as JiJiuChe ,
                        isnull(sum(case when 车辆等级编码 in (" + TransferAmbLevelCode + @")  then 1 else 0  end),0) as ZhuYuanChe ,
                        isnull(sum(case when 车辆等级编码 not in (" + NotFaAmbLevelCode + "," + FaAmbLevelCode + "," + TransferAmbLevelCode + @")   then 1 else 0  end),0) as QiTa
                        from TAmbulance ta
                        left join TStation ts on ta.分站编码=ts.编码
                        where ta.是否有效=1 and ta.工作状态编码=6 and ta.分组编码 = '" + groupCode + "'"); //取途中待命车辆

            WhereClauseUtility.AddStringEqual("ts.中心编码", CenterID, sb);
            try
            {
                DataSet ds = SqlHelper.ExecuteDataSet(SqlHelper.AttemperConnectionString, CommandType.Text, sb.ToString(), null);
                List<AmbulanceNum> list = new List<AmbulanceNum>();
                if (ds.Tables[0].Rows.Count > 0)
                {
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        AmbulanceNum info = new AmbulanceNum();
                        info.name = "急救车";
                        info.value = dr["JiJiuChe"] == DBNull.Value ? 0 : Convert.ToInt32(dr["JiJiuChe"]);
                        //info.unit = "辆";
                        list.Add(info);
                        info = new AmbulanceNum();
                        info.name = "转院车";
                        info.value = dr["ZhuYuanChe"] == DBNull.Value ? 0 : Convert.ToInt32(dr["ZhuYuanChe"]);
                        //info.unit = "辆";
                        list.Add(info);
                        info = new AmbulanceNum();
                        info.name = "非急救车";
                        info.value = dr["FeiJiJiuChe"] == DBNull.Value ? 0 : Convert.ToInt32(dr["FeiJiJiuChe"]);
                        //info.unit = "辆";
                        list.Add(info);
                        info = new AmbulanceNum();
                        info.name = "其他";
                        info.value = dr["QiTa"] == DBNull.Value ? 0 : Convert.ToInt32(dr["QiTa"]);
                        //info.unit = "辆";
                        list.Add(info);
                    }
                }
                return list;
            }
            catch (Exception ex)
            {
                LogUtility.Error("AmbulanceDAL/GetWayStandByAmbNum()", "查询失败：" + ex.Message);
                return null;
            }

        }

        /// <summary>
        /// 获取实时数据统计--站内待命车辆数
        /// </summary>
        /// <returns></returns>
        public object GetStationStandByAmbNum(string CenterID)
        {
            StringBuilder sb = new StringBuilder();
            var groupCode = ISGanBao == "true" ? AppConfig.GetConfigInt("SubAmbGroupCode") : AppConfig.GetConfigInt("MainAmbGroupCode");
            string NotFaAmbLevelCode = AppConfig.GetConfigString("NotFaAmbLevelCode"); //非急救车对应车辆等级编码
            string FaAmbLevelCode = AppConfig.GetConfigString("FaAmbLevelCode"); //急救车对应车辆等级编码
            string TransferAmbLevelCode = AppConfig.GetConfigString("TransferAmbLevelCode"); //转院车对应车辆等级编码

            //add2021-01-20 plq 添加中心筛选
            sb.Append(@"select isnull(sum(case when 车辆等级编码 in (" + NotFaAmbLevelCode + @") then 1 else 0  end),0) as FeiJiJiuChe, 
                        isnull(sum(case when 车辆等级编码 in (" + FaAmbLevelCode + @")  then 1 else 0  end),0) as JiJiuChe ,
                        isnull(sum(case when 车辆等级编码 in (" + TransferAmbLevelCode + @")  then 1 else 0  end),0) as ZhuYuanChe ,
                        isnull(sum(case when 车辆等级编码 not in (" + NotFaAmbLevelCode + "," + FaAmbLevelCode + "," + TransferAmbLevelCode + @")   then 1 else 0  end),0) as QiTa
                        from TAmbulance ta  
                        left join TStation ts on ta.分站编码=ts.编码
                        where ta.是否有效=1 and ta.工作状态编码=7 and ta.分组编码 = '" + groupCode + "'"); //取途中待命车辆
            WhereClauseUtility.AddStringEqual("ts.中心编码", CenterID, sb);

            try
            {
                DataSet ds = SqlHelper.ExecuteDataSet(SqlHelper.AttemperConnectionString, CommandType.Text, sb.ToString(), null);
                List<AmbulanceNum> list = new List<AmbulanceNum>();
                if (ds.Tables[0].Rows.Count > 0)
                {
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        AmbulanceNum info = new AmbulanceNum();
                        info.name = "急救车";
                        info.value = dr["JiJiuChe"] == DBNull.Value ? 0 : Convert.ToInt32(dr["JiJiuChe"]);
                        //info.unit = "辆";
                        list.Add(info);
                        info = new AmbulanceNum();
                        info.name = "转院车";
                        info.value = dr["ZhuYuanChe"] == DBNull.Value ? 0 : Convert.ToInt32(dr["ZhuYuanChe"]);
                        //info.unit = "辆";
                        list.Add(info);
                        info = new AmbulanceNum();
                        info.name = "非急救车";
                        info.value = dr["FeiJiJiuChe"] == DBNull.Value ? 0 : Convert.ToInt32(dr["FeiJiJiuChe"]);
                        //info.unit = "辆";
                        list.Add(info);
                        info = new AmbulanceNum();
                        info.name = "其他";
                        info.value = dr["QiTa"] == DBNull.Value ? 0 : Convert.ToInt32(dr["QiTa"]);
                        //info.unit = "辆";
                        list.Add(info);
                    }
                }
                return list;
            }
            catch (Exception ex)
            {
                LogUtility.Error("AmbulanceDAL/GetStationStandByAmbNum()", "查询失败：" + ex.Message);
                return null;
            }

        }

        /// <summary>
        /// 获取实时数据统计---实时任务中数据
        /// </summary>
        /// <returns></returns>
        public object GetCurrentTaskInfo(string CenterID)
        {
            StringBuilder sb = new StringBuilder();

            //add2021-01-17 plq  去除 干保 车辆分组的 实时任务数据(与当班车辆数据统计保持一致)
            var groupCode = ISGanBao == "true" ? AppConfig.GetConfigInt("SubAmbGroupCode") : AppConfig.GetConfigInt("MainAmbGroupCode");
            sb.Append(@"select isnull(sum(case when tae.事件类型编码=0 then 1 else 0  end),0) as JiJiu, 
                        isnull(sum(case when  tae.事件类型编码=2  then 1 else 0  end),0) as ZhuanYuan,
                        isnull(sum(case when  tae.事件类型编码=1  then 1 else 0  end),0) as FeiJiJiu, 
                        isnull(sum(case when  tae.事件类型编码 not in(0,1,2) then 1 else 0  end),0)  as QiTa
                        from TTask  tt
                        left join TAlarmEvent tae on tt.事件编码=tae.事件编码
                        left join TAmbulance tab on tab.车辆编码=tt.车辆编码
                        where 是否执行中=1 "); //取任务中数据
            sb.Append(@" and  tab.分组编码 = '" + groupCode + "'");
            WhereClauseUtility.AddStringEqual("tt.中心编码", CenterID, sb);   //add2021-01-20 plq 添加中心筛选

            try
            {
                DataSet ds = SqlHelper.ExecuteDataSet(SqlHelper.AttemperConnectionString, CommandType.Text, sb.ToString(), null);
                List<AmbulanceNum> list = new List<AmbulanceNum>();
                if (ds.Tables[0].Rows.Count > 0)
                {
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        AmbulanceNum info = new AmbulanceNum();
                        info.name = "急救";
                        info.value = dr["JiJiu"] == DBNull.Value ? 0 : Convert.ToInt32(dr["JiJiu"]);
                        //info.unit = "辆";
                        list.Add(info);
                        info = new AmbulanceNum();
                        info.name = "转院";
                        info.value = dr["ZhuanYuan"] == DBNull.Value ? 0 : Convert.ToInt32(dr["ZhuanYuan"]);
                        //info.unit = "辆";
                        list.Add(info);
                        info = new AmbulanceNum();
                        info.name = "非急救";
                        info.value = dr["FeiJiJiu"] == DBNull.Value ? 0 : Convert.ToInt32(dr["FeiJiJiu"]);
                        //info.unit = "辆";
                        list.Add(info);
                        info = new AmbulanceNum();
                        info.name = "其他";
                        info.value = dr["QiTa"] == DBNull.Value ? 0 : Convert.ToInt32(dr["QiTa"]);
                        //info.unit = "辆";
                        list.Add(info);
                    }
                }
                return list;
            }
            catch (Exception ex)
            {
                LogUtility.Error("AmbulanceDAL/GetCurrentTaskInfo()", "查询失败：" + ex.Message);
                return null;
            }

        }

    }
}
